//
//  UIViewController+PageJump.m
//  CedarFinancePH
//
//  Created by menchao on 2018/5/6.
//  Copyright © 2018年 cedarhd. All rights reserved.
//

#import "UIViewController+PageJump.h"
#import "LoginViewController.h"
#import "RealNameAuthVC.h"
#import "BindBankCardVC.h"
#import "LoginViewController.h"
#import "RealNameAuthVC.h"
#import "OrganNameAuthVC.h"
#import "BindOrganCardVC.h"


@implementation UIViewController (PageJump)

////////////////////////////////////////////////////////

//- (void)canPushToViewControllerCheckLogin:(CedarBaseViewController *)nextController{
//    if (![[CedarDataBaseStore shareInstance] getTokenForAppConfige]) {
//        LoginViewController *loginVC =  [[LoginViewController alloc]init];
//        //loginVC.logincCauseStatus = LoginCauseStatusOnlyLogin;
//        loginVC.nextController = nextController;
//        [self.navigationController pushToNewViewController:loginVC];
//    }else{
//        if (nextController) { //直接导航
//            [self.navigationController pushToNewViewController:nextController];
//        }
//    }
//}

//需要实名，绑卡
- (void)canPushToViewControllerCheckAuthBindCard:(CedarBaseViewController *)nextController{
    @weakify(self)
    LoginInfoRsp *loginRsp =  [[CedarDataBaseStore shareInstance] getLoginInfo];
    if (loginRsp.hasCertification == 2){
        UIAlertController *alert =  [AlertControllerHelper alertWithTitle:@"提示" content:@"请先完成身份认证" leftActionTitle:@"取消" rightActionTitle:@"确定" leftHandler:^{
        } rightHandler:^{
            @strongify(self)
            //未实名认证
            if ([loginRsp.organ isEqualToString:@"2"]) {
                OrganNameAuthVC *vc = [[OrganNameAuthVC alloc]init];
                vc.pageJumpToStatus = PageJumpToRiskAssessmentFromSetting;
                [self.navigationController pushToNewViewController:vc];
            }else{
                RealNameAuthVC *authVC = [[RealNameAuthVC alloc]init];
                authVC.pageJumpToStatus =  PageJumpToIgnoreNoHandle;
                [self.navigationController pushToNewViewController:authVC];
            }
        }];
        [self presentViewController:alert animated:YES completion:nil];
        return;
    }
    if (loginRsp.hasBindCard == 2){
        UIAlertController *alert =  [AlertControllerHelper alertWithTitle:@"提示" content:@"请先绑定银行卡" leftActionTitle:@"取消" rightActionTitle:@"确定" leftHandler:^{
        } rightHandler:^{
            @strongify(self)//未绑卡
            BindBankCardVC *vc = [[BindBankCardVC alloc]init];
            vc.nextController = nextController;
            [self.navigationController pushToNewViewController:vc];
        }];
        [self presentViewController:alert animated:YES completion:nil];
        return;
    }
    if (nextController) {//直接导航
        [self.navigationController pushToNewViewController:nextController];
    }
}

- (void)checkAuthBindCardWithBlock:(HandlerResultBlock)block{
    LoginInfoRsp *loginRsp =  [[CedarDataBaseStore shareInstance] getLoginInfo];
    if (loginRsp.hasCertification == 2){
        UIAlertController *alert =  [AlertControllerHelper alertWithTitle:@"提示" content:@"请先完成身份认证" leftActionTitle:@"取消" rightActionTitle:@"确定" leftHandler:^{
            //[self.navigationController popViewControllerAnimated:YES];
        } rightHandler:^{
            //未实名认证
            RealNameAuthVC *authVC = [[RealNameAuthVC alloc]init];
            [self.navigationController pushToNewViewController:authVC];
        }];
        [self presentViewController:alert animated:YES completion:nil];
        return;
    }
    if (loginRsp.hasBindCard == 2){
        UIAlertController *alert =  [AlertControllerHelper alertWithTitle:@"提示" content:@"请先绑定银行卡" leftActionTitle:@"取消" rightActionTitle:@"确定" leftHandler:^{
            //[self.navigationController popViewControllerAnimated:YES];
        } rightHandler:^{
            //未绑卡
            if ([loginRsp.organ isEqualToString:@"2"]) {
                BindOrganCardVC *vc = [[BindOrganCardVC alloc]init];
                [self.navigationController pushToNewViewController:vc];
            }else{
                BindBankCardVC *vc = [[BindBankCardVC alloc]init];
                [self.navigationController pushToNewViewController:vc];
            }
        }];
        [self presentViewController:alert animated:YES completion:nil];
        return;
    }
    if (block) {
        block(JumpAuthTypeScuess);
    }
}



@end
